package hibernatenormal;

import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * Hibernate Utility class with a convenient method to get Session Factory
 * object.
 */
public class HibernateUtil {

    private static final SessionFactory sessionFactory;
    private static String URL_conexion = "jdbc:mysql://localhost:3306/sistemaplanilla?zeroDateTimeBehavior=convertToNull";
    private static String usuario_conexion = "root";
    private static String contrasenna_conexion = "root";

    static {
        try {
            // Create the SessionFactory from standard (hibernate.cfg.xml) 
            // config file.
            Configuration configuration = new Configuration().configure();
            sessionFactory = configuration.buildSessionFactory();
            URL_conexion = configuration.getProperty("hibernate.connection.url");
            usuario_conexion = configuration.getProperty("hibernate.connection.username");
            contrasenna_conexion = configuration.getProperty("hibernate.connection.password");
        } catch (HibernateException ex) {
            // Log the exception. 
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public static String getURL_conexion() {
        return URL_conexion;
    }

    public static String getUsuario_conexion() {
        return usuario_conexion;
    }

    public static String getContrasenna_conexion() {
        return contrasenna_conexion;
    }
}
